package com.morder.net;

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;

/**
 * Get apn info.
 */
final class ApnProvider {
  private ApnProvider() {
  }

  static final Uri PREFERRED_APN_URI = Uri.parse("content://telephony/carriers/preferapn");

  public static Apn getDefaultApn(Context ctx) {
    String proxy = "";
    int port = 0;
    Cursor mCursor = ctx.getContentResolver().query(PREFERRED_APN_URI, null, null, null, null);
    if(mCursor != null) {
      mCursor.moveToFirst();
      if(!mCursor.isAfterLast()) {
        String p = mCursor.getString(mCursor.getColumnIndex("proxy"));
        if(p != null) {
          proxy = p;
        }
        proxy = proxy.trim();

        port = mCursor.getInt(mCursor.getColumnIndex("port"));
      }
    }

    return new Apn(proxy, port);
  }

}
